﻿using UnityEngine;
using System.Collections.Generic;
using System;

namespace YanhuaMMO {

    /// <summary>
    /// </summary>
    public class Main : MonoBehaviour {

        public static Queue<Action> uItask = new Queue<Action>();

        public float updateInterval = 0.5F;
        private double lastInterval;
        private int frames = 0;
        private float fps;
        GUIStyle myStyle = new GUIStyle();


        public static void invokeTask(Action action)
        {
            uItask.Enqueue(action);
        }

        void Start() {
            AppFacade.Instance.StartUp();   //启动游戏
            lastInterval = Time.realtimeSinceStartup;
            frames = 0;
            //BuglyAgent.ConfigDebugMode (true);

            //#if UNITY_IPHONE || UNITY_IOS
            //    BuglyAgent.InitWithAppId ("6506508167");
            //#elif UNITY_ANDROID
            //    BuglyAgent.InitWithAppId ("6506508167");
            //#endif

    
            //BuglyAgent.EnableExceptionHandler ();
            //myStyle.fontSize = 28;
            //myStyle.normal.textColor = Color.red;

            // Debug.LogError("Application.targetFrameRate 1: " + Application.targetFrameRate);
            // Application.targetFrameRate = 60;
            // Debug.LogError("Application.targetFrameRate 2: " + Application.targetFrameRate);

        }
        //void OnGUI()
        //{

        //    GUILayout.Label(" " + AppConst.debugMsg, myStyle);
        //}
        private void Update()
        {
            if (uItask.Count > 0)
            {
                Action action = uItask.Dequeue();

                action();
            }
            //++frames;
            //float timeNow = Time.realtimeSinceStartup;
            //if (timeNow > lastInterval + updateInterval)
            //{
            //    fps = (float)(frames / (timeNow - lastInterval));
            //    frames = 0;
            //    lastInterval = timeNow;
            //}
        }
    }
}